package org.hxzon.workeasy.pages.visitor;

import org.apache.tapestry5.EventConstants;
import org.apache.tapestry5.annotations.InjectPage;
import org.apache.tapestry5.annotations.OnEvent;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.hxzon.workeasy.model.EasyUzer;
import org.hxzon.workeasy.pages.base.MyBasePage;
import org.hxzon.workeasy.pages.user.ViewUser;
import org.hxzon.workeasy.service.EasyUserService;
import org.hxzon.workeasy.util.HlogConstants;
import org.slf4j.Logger;

public class EditVisitor extends MyBasePage {
    @Inject
    private Logger logger;
    @Inject
    private EasyUserService userSer;
    @Property
    private EasyUzer user;
    @InjectPage
    private ViewUser viewUser;

    @OnEvent(value = EventConstants.ACTIVATE)
    Object init() {
        //init for display or update
        user = getVisitor();
        return null;
    }

    @OnEvent(value = EventConstants.SUCCESS, component = "updateInfo")
    Object updateInfo() {
//		mustSelf();
        EasyUzer visitor = getVisitor();
        visitor.md5password();
        userSer.save(visitor);
        hlog(HlogConstants.updateUserInfo, visitor);
        logger.info("change user info", visitor);
        return viewUser.initialize(getVisitor().getId());
    }
}
